/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package daos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trietto
 */
public class DBConnection {
    static Connection conn = null;
    public static Connection getConnection(){
        if(conn==null){
            try {
                //Register the JDBC driver for MySQL.
                Class.forName("com.mysql.jdbc.Driver");
                //Define URL of database server for
                // database named mysql on the localhost
                // with the default port number 3306.
                String url = "jdbc:mysql://localhost:3306/bookstore";
                //Get a connection to the database for a
                // user named root with a blank password.
                // This user is the default administrator
                // having full privileges to do anything.
                conn = DriverManager.getConnection(url, "root", "18121979");
            } catch (Exception ex) {
                Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return conn;
    }
}
